package top.drinyeit.weilong.util;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.view.View;

/**
 * Created by Erebus on 2016/11/26.
 */
public class TransitionUtil {

    public static void transitionToActivity(Activity fromActivity, Class target, Bundle bundle) {
        final Pair<View, String>[] pairs = TransitionHelper.createSafeTransitionParticipants(fromActivity, true);
        startActivity(fromActivity, target, pairs, bundle);
    }

    public static void transitionToActivity(Activity fromActivity, Class target, Bundle bundle, View... views) {
        final Pair<View, String>[] pairs = TransitionHelper.createSafeTransitionParticipants(fromActivity, true, views);
        startActivity(fromActivity, target, pairs, bundle);
    }


    private static void startActivity(Activity fromActivity, Class target, Pair<View, String>[] pairs, Bundle bundle) {
        Intent intent = new Intent(fromActivity, target);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        ActivityOptionsCompat transitionActivityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(fromActivity, pairs);
        if (bundle != null) intent.putExtras(bundle);
        fromActivity.startActivity(intent, transitionActivityOptions.toBundle());
    }
}
